<?php
class cmshopapi_GetToken extends cmshopApi_base
{
    var $verb='GetToken';
    var $fields=array(
        
    );
    function Request(){
        //验证 sessionid
        if($this->stringInput('RuName')!='GetToken'){
            throw new Exception_RequestFormatInvalidate('');
        }
        if(strlen($this->stringInput('sessionid'))<=0){
            throw new Exception_RequestFormatInvalidate('');
        }
        $s=Sessionid::find('sessionid=? And hardexpirationtime>=?',$this->stringInput('sessionid'),CURRENT_TIMESTAMP)->getOne();
        if($s->isNewRecord()) throw new Exception_AuthTokenInvalidate('');
        // 找 token 
        if(strlen($s->data)){
            $token=Token::find('token=? And hardexpirationtime>=?',$s->data,CURRENT_TIMESTAMP)->getOne();
            
            echo $this->Response(array(
                'token'=>$token->token,
                'seller_name'=>$token->seller->seller_name,
                'store_name'=>$token->store->name,
                'hardexpirationtime'=>$this->dateTime($token->hardexpirationtime)
            ));
            die();
        }else{
            throw new Exception_AuthTokenInvalidate('');
        }
    }
    
    // 回给 客户  .
    function Response($attr){
		$xmlArr=array(
            'Ack'=>'Success',
            'timestamp'=>$this->dateTime(),
		) +$attr;
        return $this->xmlresponse($xmlArr);
    }

}